﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ExtBusiness;
using System.Data.OracleClient;

/// <summary>
/// 添加web页面的后台
/// </summary>
public partial class WebPubManager : PageBase
{
    private string strId = string.Empty;
    private string strBsznName = ConfigurationManager.AppSettings["bsznName"];
    private WebOtherManager cManager = new WebOtherManager();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request["id"]))
        {
            strId = Request["id"];
        }

        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request["type"]))
            {
                labMsg.Text = Request["type"];
            }
            if (!string.IsNullOrEmpty(Request["datatype"]))
            {
                ddlYwlx.DefaultValue = Request["datatype"];
            }

            if (labMsg.Text == strBsznName)
            {
                trZt.Visible = false;
                trYwlx.Visible = false;
                trTjlx.Visible = false;
                btnReturn.Visible = false;
            }
            else
            {
                trYwlx.Visible = true;
            }

            DataTable dtSource=new DataTable();
            if (!string.IsNullOrEmpty(strId))//通过id定位
            {
                dtSource = cManager.GetOther(strId);
            }
            else
            {
                //通过大类和小类定位一条记录
                if (!string.IsNullOrEmpty(labMsg.Text) && !string.IsNullOrEmpty(ddlYwlx.DefaultValue))
                {
                    if (!string.IsNullOrEmpty(Request["flowid"]))//当是办事指南时才定位 update by zhongjian 20091209
                    {
                        dtSource = cManager.GetOther(ddlYwlx.DefaultValue, labMsg.Text);
                    }
                }
            }

            if (dtSource.Rows.Count > 0)
            {
                txt_title.Text = dtSource.Rows[0]["TITLE"].ToString();
                FreeTextBox1.Text = dtSource.Rows[0]["CONTENT"].ToString();
                ddlYwlx.DefaultValue = dtSource.Rows[0]["SMALLTYPE"].ToString();
                ddlYwlx.ReadOnly = true;
                ckbNotice.Checked = dtSource.Rows[0]["is_notice"].ToString()=="1"?true:false;
            }
        }
    }

    /// <summary>
    /// 数据保存
    /// </summary>
    private void UpdateData()
    {
        try
        {
            string strTitle = string.Empty;
            if (labMsg.Text == strBsznName)
            {
                strTitle = ddlYwlx.Text;
            }
            else
            {
                strTitle = txt_title.Text;
            }

            int nNotice = ckbNotice.Checked == true ?1 : 0;
            if (nNotice == 1)
            {
                WebOtherManager.UpdateIsNotice();
            }

            if (string.IsNullOrEmpty(strId))
            {
                string strCount = "0";
                if (labMsg.Text == strBsznName)
                {
                    strCount = cManager.GetCount(strTitle, labMsg.Text);
                }

                if (strCount == "0")
                {
                    WebOtherManager.InsertManage(strTitle, labMsg.Text, ddlYwlx.Text,
                        nNotice.ToString(), FreeTextBox1.Text);
                }
                else//办事指南
                {
                    //string strScript = "<script>confirm('此标题已有内容，确定修改该内容?');</script>";
                    //ClientScript.RegisterStartupScript(this.GetType(), "regSave", strScript);
                    WebOtherManager.UpdateManages(ddlYwlx.Text, labMsg.Text,
                        nNotice.ToString(), FreeTextBox1.Text);
                }
            }
            else
            {
                if (labMsg.Text == strBsznName)
                {
                    //string strScript = "<script>confirm('此业务类型已有内容，该操作将修改此业务类型的内容，而不会对原业务类型更改。确定修改该内容?');</script>";
                    //ClientScript.RegisterStartupScript(this.GetType(), "regSave", strScript);
                    WebOtherManager.UpdateManages(strTitle, labMsg.Text,
                        nNotice.ToString(), FreeTextBox1.Text);
                }
                else
                {
                    WebOtherManager.UpdateManagesId(strId, nNotice.ToString(), ddlYwlx.Text,
                        FreeTextBox1.Text, strTitle);
                }
            }

            labError.Text = "操作成功！";

            //清空数据
            //this.FreeTextBox1.Text = "";
        }
        catch (Exception ex)
        {
            labError.Text = ex.Message;
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {     
         UpdateData();
         //刷新父页面,关闭本页面 addby zhongjian 20091111
         Response.Write("<script>window.opener.location.reload();window.close();</script>");
    }

    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("WorkFlowPub.aspx");
        //为跳出上一级框架 edit by zhongjian 20091010
        //Response.Write("<script>parent.location.href='WebPubManager/WorkFlowManager.aspx';</script>");
    }
}
